// let condition = true;
// if(condition){
//     function showName()
//     {
//         console.log('Smith')
//     }
//     } else {
//     function showName()
//     {
//         console.log('Alice')
//     }
//     }
// showName();

//创建函数并赋值给变量的能力也可以用于在一个函数中把另一个函数当作值返回
function createCompareFunction(propereName){
    return function(obj1,obj2){
        let objValue1 = obj1[propereName];
        let objValue2 = obj2[propereName];
        if(objValue1 > objValue2){
            return 1;
        }
        if(objValue1 === objValue2){
            return 0;
        }
        if(objValue1 < objValue2){
            return -1;
        }
    }
}
let person1 = {
    age:25
}
let person2 = {
    age:36
}
let compareFunction = createCompareFunction('age');
console.log(compareFunction(person1,person2));//-1